var aOneAdd1Test = (function () {

  var aOneAdd1Test = {};

  var execTest = {};

  function actionTest(action) {
    console.log(action.getStorage());
    console.log(action.canFlow());
    action.flow();
  }
  function appTest(app) {
    app.main();
  }

  execTest.actionTest = actionTest;
  execTest.appTest = appTest;

  var MAX_SEARCH_TIME = 10000; //搜索控件时超时时间 http://doc.autoxjs.com/#/widgetsBasedAutomation?id=uiselectorfindonetimeout
  var show = console.show;
  var hide = console.hide;
  console.show = function () {
    this.showing = true;
    show.apply(console, arguments);
  };
  console.hide = function () {
    this.showing = false;
    hide.apply(console, arguments);
  };

  function bezier_curves(cp, t) {
    cx = 3.0 * (cp[1].x - cp[0].x);
    bx = 3.0 * (cp[2].x - cp[1].x) - cx;
    ax = cp[3].x - cp[0].x - cx - bx;
    cy = 3.0 * (cp[1].y - cp[0].y);
    by = 3.0 * (cp[2].y - cp[1].y) - cy;
    ay = cp[3].y - cp[0].y - cy - by;

    tSquared = t * t;
    tCubed = tSquared * t;
    result = {
      x: 0,
      y: 0,
    };
    result.x = ax * tCubed + bx * tSquared + cx * t + cp[0].x;
    result.y = ay * tCubed + by * tSquared + cy * t + cp[0].y;
    return result;
  }

  //仿真随机带曲线滑动
  //qx, qy, zx, zy, time 代表起点x,起点y,终点x,终点y,过程耗时单位毫秒
  function sml_move(qx, qy, zx, zy, time) {
    var xxy = [time];
    var point = [];
    var dx0 = {
      x: qx,
      y: qy,
    };

    var dx1 = {
      x: random(qx - 100, qx + 100),
      y: random(qy, qy + 50),
    };
    var dx2 = {
      x: random(zx - 100, zx + 100),
      y: random(zy, zy + 50),
    };
    var dx3 = {
      x: zx,
      y: zy,
    };
    point.push(dx0);
    point.push(dx1);
    point.push(dx2);
    point.push(dx3);

    for (let i = 0; i < 1; i += 0.08) {
      xxyy = [
        parseInt(bezier_curves(point, i).x),
        parseInt(bezier_curves(point, i).y),
      ];

      xxy.push(xxyy);
    }

    gesture.apply(null, xxy);
  }
  var utils$8 = {
    storage: {
      get() {},
      set() {},
    },
    clickOcrText(ocrText) {
      this.clickBounds(ocrText.bounds);
    },
    clickOcrItem(ocrItem) {
      this.clickBounds(ocrItem.bounds);
    },
    getOcrItemPoint(ocrItem) {
      var bounds = ocrItem.bounds;
      var left = bounds.left;
      var right = bounds.right;
      var top = bounds.top;
      var bottom = bounds.bottom;
      return {
        x: random(left + 1, right - 1),
        y: random(top + 1, bottom - 1),
      };
    },
    clickUIControl(UIControl) {
      //点击ui控件
      while (true) {
        if (UIControl && UIControl.clickable()) {
          UIControl.click();
          return true;
        } else if (UIControl) {
          UIControl = UIControl.parent();
        } else {
          return false;
        }
      }
    },
    clickUIText(textUI) {
      var bounds = textUI.bounds();
      this.clickBounds(bounds);
    },

    getUITextPoint(UIText) {
      return {
        x: UIText.bounds().centerX(),
        y: UIText.bounds().centerY(),
      };
    },
    existsTextStartsWith(content, ignoreLog) {
      if (textStartsWith(content).exists()) {
        var UIText = textStartsWith(content).findOne(MAX_SEARCH_TIME);
        if (!ignoreLog && UIText) {
          console.log(
            "existsTextStartsWith",
            "找到:",
            content,
            "/",
            UIText.text()
          );
        }
        return UIText;
      } else {
        return false;
      }
    },
    existsText(content, ignoreLog) {
      if (text(content).exists()) {
        var UIText = text(content).findOne(MAX_SEARCH_TIME);
        if (!ignoreLog && UIText) {
          console.log("existsText", "找到:", content, "/", UIText.text());
        }
        return UIText;
      } else {
        return false;
      }
    },
    clickText(content, ignoreLog) {
      if (this.existsText(content, true)) {
        var UIText = text(content).findOne(MAX_SEARCH_TIME);
        var bounds = UIText.bounds();
        if (!ignoreLog) {
          console.log("clickText", "找到:", content, "/", UIText.text());
        }
        this.clickBounds(bounds);
        return UIText;
      } else {
        return false;
      }
    },
    existsOneTextStartsWith(content, ignoreLog) {
      if (!Array.isArray(content)) {
        content = [content];
      }
      for (var index = 0; index < content.length; index++) {
        var item = content[index];
        var result = this.existsTextStartsWith(item, true);
        if (!ignoreLog && result) {
          console.log(
            "existsOneTextStartsWith",
            "找到:",
            item,
            "/",
            result.text()
          );
          return result;
        }
      }
    },
    clickTextStartsWith(content, ignoreLog) {
      var UIText = this.existsTextStartsWith(content, true);
      if (UIText) {
        var bounds = UIText.bounds();
        if (!ignoreLog) {
          console.log(
            "clickTextStartsWith",
            "找到:",
            content,
            "/",
            UIText.text()
          );
        }
        this.clickBounds(bounds);
        return UIText;
      } else {
        return false;
      }
    },
    existsTextEndsWith(content, ignoreLog) {
      if (textEndsWith(content).exists()) {
        var UIText = textEndsWith(content).findOne(MAX_SEARCH_TIME);
        if (!ignoreLog && UIText) {
          console.log(
            "existsTextEndsWith",
            "找到：",
            content,
            "/",
            UIText.text()
          );
        }
        return UIText;
      } else {
        return false;
      }
    },
    clickTextEndsWith(content, ignoreLog) {
      var UIText = this.existsTextEndsWith(content, true);
      if (UIText) {
        var bounds = UIText.bounds();
        if (!ignoreLog) {
          console.log("clickTextEndsWith", "找到：", content, "/", UIText.text());
        }
        this.clickBounds(bounds);
        return UIText;
      } else {
        return false;
      }
    },
    existsTextMatches(content, ignoreLog) {
      if (textMatches(content).exists()) {
        var UIText = textMatches(content).findOne(MAX_SEARCH_TIME);
        if (!ignoreLog) {
          console.log("existsTextMatches", "找到：", content, "/", UIText.text());
        }
        return UIText;
      } else {
        return false;
      }
    },
    clickTextMatches(content, ignoreLog) {
      var UIText = this.existsTextMatches(content, true);
      if (UIText) {
        if (!ignoreLog) {
          console.log("clickTextMatches", "找到：", content, "/", UIText.text());
        }
        var bounds = UIText.bounds();
        this.clickBounds(bounds);
        return UIText;
      } else {
        return false;
      }
    },
    clickBounds(bounds) {
      var left = bounds.left;
      var right = bounds.right;
      var top = bounds.top;
      var bottom = bounds.bottom;
      return this.clickXY(
        random(left + 1, right - 1),
        random(top + 1, bottom - 1)
      );
    },
    clickPoint(x1, y1, x2, y2) {
      var x = utils$8.getRandom(x1 + 1, x2 - 1);
      var y = utils$8.getRandom(y1 + 1, y2 - 1);
      this.clickXY(x, y);
      // var point = this.getCenterPoint(x1, y1, x2, y2);
      // return this.clickXY(point.x, point.y);
    },
    clickXY(x, y) {
      console.log("clickXY", x, y);
      return click(x, y);
    },
    getSizePoint(points, w, h) {
      var length = points.length;
      var sizePoints = [];
      var rateX = device.width / (w || 720);
      var rateY = device.height / (h || 1650);
      for (var i = 0; i < length; i++) {
        var point = points[i];
        var rate = i % 2 == 0 ? rateX : rateY;
        sizePoints.push(parseInt(point * rate));
      }
      return sizePoints;
    },
    getCenterPoint(x1, y1, x2, y2) {
      return {
        x: random(x1 + 1, x2 - 1),
        y: random(y1 + 1, y2 - 1),
      };
      // return {
      //   x: parseInt(x1 + (x2 - x1) / 2),
      //   y: parseInt(y1 + (y2 - y1) / 2),
      // };
    },
    getNumber(content) {
      var REGEXP = /(\d+)/g;
      var match = content.match(REGEXP);
      return parseInt(match ? match[0] : 0);
    },
    clickPointMap(pointMap) {
      var points = pointMap.points;
      var size = pointMap.size;
      this.clickPoint.apply(this, this.getSizePoint(points, size.x, size.y));
    },
    getRandom(start, end, times) {
      var times = times || 1;
      return random(start * times, end * times);
    },
    createLogger() {
      var arguments1 = [];
      var length = arguments.length;
      for (var index = 0; index < length; index++) {
        arguments1.push(arguments[index]);
      }
      return function () {
        var arguments2 = [];
        var length = arguments.length;
        for (var index = 0; index < length; index++) {
          arguments2.push(arguments[index]);
        }
        console.log.apply(console.log, arguments1.concat(arguments2));
      };
    },
    createLoggerX(prefix, count) {
      var arguments1 = [prefix];
      var execCount = 0;
      count = count || 1;
      return function () {
        var arguments2 = [];
        var length = arguments.length;
        for (var index = 0; index < length; index++) {
          arguments2.push(arguments[index]);
        }
        execCount = execCount + 1;
        if (execCount % count == 0) {
          console.log.apply(console.log, arguments1.concat(arguments2));
        }
      };
    },
    randomIndexArray(max) {
      var result = [];
      while (result.length < max) {
        var number = random(0, max - 1);
        if (result.indexOf(number) == -1) {
          result.push(number);
        }
      }
      return result;
    },
    swipe(a, b, c, d) {
      swipe(
        device.width * a * this.getRandom(95, 5, 1),
        device.height * b * this.getRandom(95, 5, 1),
        device.width * c * this.getRandom(95, 5, 1),
        device.height * d * this.getRandom(95, 5, 1),
        utils$8.getRandom(2, 8, 100)
      );
    },
    swipeX(qx, qy, zx, zy, time) {
      sml_move(qx, qy, zx, zy, time);
    },
    strFormat(str, str2) {
      if (!str) {
        return "";
      }
      str2 = str2 || "哈";
      return str.split("").join(str2);
    },
    merge(a, b, c) {
      for (var prop in c) {
        a[prop] = b[prop] || c[prop];
      }
    },
    getStorage(key) {
      return storages.create(key);
    },
  };

  var utils_1 = utils$8;

  var dateRegex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:\/]*)/g;
  var timeSpan = {
    YYYY: ["getFullYear", 4],
    YY: ["getFullYear", 2],
    MM: ["getMonth", 2, 1], // getMonth is zero-based, thus the extra increment field
    DD: ["getDate", 2],
    HH: ["getHours", 2],
    mm: ["getMinutes", 2],
    ss: ["getSeconds", 2],
    ms: ["getMilliseconds", 3],
  };
  var time$1 = {};

  time$1.str = function (str, date, utc) {
    if (typeof str !== "string") {
      date = str;
      str = "YYYY-MM-DD HH:mm:ss";
    }

    if (!date) date = new Date();
    return str.replace(dateRegex, function (match, key, rest) {
      var args = timeSpan[key];
      var name = args[0];
      var chars = args[1];
      if (utc === true) name = "getUTC" + name.slice(3);
      var val = "00" + String(date[name]() + (args[2] || 0));
      return val.slice(-chars) + (rest || "");
    });
  };

  time$1.utc = function (str, date) {
    return time$1(str, date, true);
  };

  var time_1 = time$1;

  var utils$7 = utils_1;

  if (!requestScreenCapture()) {
    toastLog("请求截图权限失败");
    exit();
  }

  function toArray(arrLike) {
    var array = [];
    for (var index = 0; index < arrLike.length; index++) {
      array.push(arrLike[index]);
    }
    return array;
  }

  function getCaptureImg() {
    var startTime = Date.now();
    // console.log("getCaptureImg: 开始截图");
    var consoleShowing = console.showing;
    if (consoleShowing) {
      console.hide();
      sleep(0.1 * 1000);
    }
    var captureImg = captureScreen();
    if (consoleShowing) {
      console.show();
    }
    if (!captureImg) {
      toastLog("截图失败");
    }
    var endTime = Date.now();
    console.log("getCaptureImg: 截图耗费-" + (endTime - startTime) / 1000 + "-s");
    return captureImg;
  }

  function getCaptureImgOcrResult() {
    var captureImg = getCaptureImg();
    var captureImgOrcResults = toArray(gmlkit.ocr(captureImg, "zh").toArray(3));
    setTimeout(() => {
      captureImg.recycle();
    });
    return captureImgOrcResults;
  }

  var OCR_UTIL_CONST_CHAR_MATCH_MAP = {
    搜: ["嫂", "樓", "接", "楼"],
    赚: ["廉", "嫌", "賺", "兼"],
    看: ["着", "春"],
    文: ["女"],
    章: ["拿"],
    钱: ["线"],
    觉: ["党"],
    户: ["戶"],
    索: ["素"],
    开: ["升", "研"],
    金: ["全"],
    积: ["枳"],
    币: ["市"],
    现: ["現"],
    领: ["領", "颌"],
    读: ["渎"],
    额: ["額"],
    取: ["驭"],
    视: ["规", "初"],
    享: ["亨"],
    兑: ["兌"],
    提: ["堤"],
    体: ["休"],
    才: ["オ"],
    街: ["衔"],
    城: ["械"],
    间: ["闻"],
    来: ["來"],
    十: ["+"],
    补: ["朴"],
    贴: ["貼"],
    接: ["按"],
    倍: ["信"],
    进: ["避"],
  };

  var ocrGml$3 = {
    getRegExp(content) {
      var regExpStr = content
        .split("")
        .map(function (item) {
          if (item == "D") {
            return "\\d*";
          }
          var match = OCR_UTIL_CONST_CHAR_MATCH_MAP[item];
          var piece = match
            ? "[" + match.concat(item).join("") + "]+"
            : "[" + item + "]+";
          return piece + "\\s*";
        })
        .join("");
      return {
        text: content,
        regExp: new RegExp(regExpStr, "gi"),
      };
    },
    toArray: toArray,
    captureAndLogText() {
      var captureImgOrcResults = getCaptureImgOcrResult();
      console.log(
        "captureAndLogText:",
        captureImgOrcResults.map((item) => item.text).join("\n")
      );
    },
    captureExistAll(content, logInfo) {
      var logger = utils$7.createLogger("ocrGml captureExistAll: ");
      if (!Array.isArray(content)) {
        content = [content];
      }
      var contentConfigs = content.map((item) => {
        return {
          text: content,
          regExp: this.getRegExp(item).regExp,
          find: null,
        };
      });
      // if (logInfo) {
      //   logger(
      //     "正则表达式是-" +
      //       contentConfigs.map((item) => item.regExp.toString()).join(" || ") +
      //       "-"
      //   );
      // }
      var captureImgOrcResults = getCaptureImgOcrResult();
      for (var index = 0; index < captureImgOrcResults.length; index++) {
        var item = captureImgOrcResults[index];
        for (var j = 0; j < contentConfigs.length; j++) {
          var contentConfig = contentConfigs[j];
          if (!contentConfig.find && contentConfig.regExp.test(item.text)) {
            contentConfig.find = item;
            break;
          }
        }
        if (contentConfigs.every((item) => item.find)) {
          break;
        }
      }
      if (contentConfigs.some((item) => !item.find)) {
        if (logInfo) {
          var noFinds = contentConfigs
            .filter((item) => !item.find)
            .map((item) => item.text)
            .join(" || ");
          logger("没找到-" + utils$7.strFormat(noFinds) + "-");
          this.logText(captureImgOrcResults);
        }
        return false;
      }
      return true;
    },
    captureExistOne(content, logInfo) {
      if (!Array.isArray(content)) {
        content = [content];
      }
      var configs = content.map((item) => {
        return this.getRegExp(item);
      });
      // if (logInfo) {
      //   console.log(
      //     "ocrGml captureExistOne: " +
      //       "正则表达式是：-" +
      //       configs.map((item) => item.regExp).join(" || ") +
      //       "-"
      //   );
      // }
      return this.captureMatchOne(configs, logInfo);
    },
    captureMatchOne(regExpConfigs, logInfo) {
      var captureImgOrcResults = getCaptureImgOcrResult();
      for (var index = 0; index < captureImgOrcResults.length; index++) {
        var item = captureImgOrcResults[index];
        var find = regExpConfigs.find((regExpConfig) => {
          return regExpConfig.regExp.test(item.text);
        });
        if (find && logInfo) {
          console.log(
            "captureMatchOne: 找到-",
            utils$7.strFormat(item.text + "|" + find.text) + "-"
          );
          return item;
        }
      }
      if (logInfo) {
        console.log(
          "ocrGml captureMatchOne: 没找到: ",
          utils$7.strFormat(regExpConfigs.map((item) => item.text).join(" || "))
        );
        this.logText(captureImgOrcResults);
      }
    },
    logText(captureImgOrcResults) {
      console.log(
        captureImgOrcResults
          .map(function (item) {
            return item.text;
          })
          .join("|")
      );
    },
    findTextOne(content, logInfo, ifIsEnd, maxSwipeTimes, swipeInstace) {
      if (!Array.isArray(content)) {
        content = [content];
      }
      maxSwipeTimes = maxSwipeTimes || 10;
      logInfo = logInfo || false;
      swipeInstace = swipeInstace || (device.height / 10) * 1;
      var regExpConfigs = content.map((item) => {
        return this.getRegExp(item);
      });
      var result = this.captureMatchOne(regExpConfigs, logInfo);
      if (result) {
        return result;
      }
      if (maxSwipeTimes == 1) {
        return;
      }
      maxSwipeTimes = maxSwipeTimes - 1;
      while (maxSwipeTimes > 0) {
        sleep(utils$7.getRandom(1, 1.5, 1000));
        utils$7.swipeX(
          ((device.width / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.height / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.width / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.height / 2 - swipeInstace) * utils$7.getRandom(90, 100)) / 100,
          utils$7.getRandom(500, 1000)
        );
        var result = this.captureMatchOne(regExpConfigs, logInfo);
        if (result) {
          return result;
        }
        maxSwipeTimes = maxSwipeTimes - 1;
        if (ifIsEnd && ifIsEnd()) {
          break;
        }
      }
    },
    findTextAll(content, logInfo, ifIsEnd, maxSwipeTimes, swipeInstace) {
      var logger = utils$7.createLogger("ocrGml findTextAll: ");
      if (!Array.isArray(content)) {
        content = [content];
      }
      var contentConfigs = content.map((item) => {
        return {
          text: item,
          regExp: this.getRegExp(item).regExp,
          result: null,
        };
      });
      if (logInfo) {
        logger(
          "正则表达式是： -" +
            contentConfigs.map((item) => item.regExp).join(" || ") +
            "-"
        );
      }
      maxSwipeTimes = maxSwipeTimes || 10;
      logInfo = logInfo || false;
      swipeInstace = swipeInstace || (device.height / 10) * 1;
      var ocrTextResults = [];
      while (maxSwipeTimes > 0) {
        var captureImgOrcResults = getCaptureImgOcrResult();
        for (var index = 0; index < captureImgOrcResults.length; index++) {
          var item = captureImgOrcResults[index];
          for (var j = 0; j < contentConfigs.length; j++) {
            var contentConfig = contentConfigs[j];
            var text = contentConfig.text;
            var regExp = contentConfig.regExp;
            var find = ocrTextResults.find(function (item) {
              return item.text == text;
            });
            if (!find && regExp.test(item.text)) {
              ocrTextResults.push({
                text,
                regExp,
                result: item,
              });
              logger("找到-" + utils$7.strFormat(item.text) + "-");
              break;
            }
          }
          if (ocrTextResults.length == contentConfigs.length) {
            break;
          }
        }
        if (ocrTextResults.length > 0) {
          return ocrTextResults;
        }
        if (ocrTextResults.length == 0) {
          if (logInfo) ; else {
            logger(
              "当前页面没有找到-" +
                utils$7.strFormat(
                  contentConfigs.map((item) => item.text).join(" || ")
                )
            );
          }
        }
        utils$7.swipeX(
          ((device.width / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.height / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.width / 2) * utils$7.getRandom(90, 100)) / 100,
          ((device.height / 2 - swipeInstace) * utils$7.getRandom(90, 100)) / 100,
          utils$7.getRandom(500, 1000)
        );
        sleep(utils$7.getRandom(1, 1.5, 1000));
        maxSwipeTimes = maxSwipeTimes - 1;
        if (ifIsEnd && ifIsEnd()) {
          return ocrTextResults;
        }
      }
      return ocrTextResults;
    },
  };

  var ocrGml_1 = ocrGml$3;

  var common$2 = {};

  var utils$6 = utils_1;
  function swipeUp$2() {
    utils$6.swipeX(
      ((device.width / 10) * 5 * utils$6.getRandom(90, 100, 1)) / 100,
      ((device.height / 10) * 5 * utils$6.getRandom(90, 100, 1)) / 100,
      ((device.width / 10) * 5 * utils$6.getRandom(90, 100, 1)) / 100,
      ((device.height / 10) * 2 * utils$6.getRandom(90, 100, 1)) / 100,
      utils$6.getRandom(0.5, 1.2, 1000)
    );
  }
  var swipeUp_1 = swipeUp$2;

  var utils$5 = utils_1;
  function swipeDown$2() {
    utils$5.swipeX(
      ((device.width / 10) * 5 * utils$5.getRandom(90, 100, 1)) / 100,
      ((device.height / 10) * 3 * utils$5.getRandom(90, 100, 1)) / 100,
      ((device.width / 10) * 5 * utils$5.getRandom(90, 100, 1)) / 100,
      ((device.height / 10) * 9 * utils$5.getRandom(90, 100, 1)) / 100,
      utils$5.getRandom(0.5, 1.2, 1000)
    );
  }
  var swipeDown_1 = swipeDown$2;

  var utils$4 = utils_1;
  var swipeUp$1 = swipeUp_1;
  var swipeDown$1 = swipeDown_1;
  function readArticle$1(span, maxUp) {
    var maxUp = maxUp || 5;
    var swipeTimes = 0;
    var startTime = Date.now();
    var count = 0;
    while (true) {
      count = count + 1;
      var randomNumber = utils$4.getRandom(0, 100);
      if (swipeTimes < maxUp) {
        if (count % 5 == 0) {
          console.log("向上滑动一次");
        }
        swipeUp$1();
      } else {
        if (randomNumber > 90) {
          if (count % 5 == 0) {
            console.log("向下滑动一次");
          }
          swipeDown$1();
        } else {
          if (count % 5 == 0) {
            console.log("向上滑动一次");
          }
          swipeUp$1();
        }
      }
      var watchContentSpan = utils$4.getRandom(1.5, 3, 1000);
      sleep(watchContentSpan);
      swipeTimes = swipeTimes + 1;
      var endTime = Date.now();
      if (count % 5 == 0) {
        console.log("已看内容-" + (endTime - startTime) / 1000 + "-s");
      }
      if (endTime - startTime >= span * 1000) {
        break;
      }
    }
  }

  var readArticle_1 = readArticle$1;

  var utils$3 = utils_1;
  var time = time_1;
  var ocrGml$2 = ocrGml_1;
  var readArticle = readArticle_1;
  var swipeUp = swipeUp_1;
  var swipeDown = swipeDown_1;
  var pointMap = {
    首页任务: {
      points: [
        // prettier-ignore
        656, 2136, 858, 2296,
      ],
      size: {
        x: 1080,
        y: 2340,
      },
    },
    首页我的: {
      points: [
        // prettier-ignore
        858, 2136, 1061, 2296,
      ],
      size: {
        x: 1080,
        y: 2340,
      },
    },
  };
  function inHome() {
    // prettier-ignore
    var contents = [
            "百度",
            "听书"
        ];
    var result = ocrGml$2.captureExistAll(contents);
    if (result) {
      console.log("找到-" + contents.join("和") + "-,判断在首页");
    } else {
      console.log("没找到-" + contents.join("和") + "-");
    }
    return result;
  }
  function toTask() {
    console.log("前往-首页任务-");
    utils$3.clickPointMap(pointMap["首页任务"]);
  }

  function ifHasNextAdDefault() {
    var contents = [
      //prettier-ignore
      "看视频领",
      "看视频再领",
      "看视频再得",
      "看广告领",
      "看广告再领",
      "看广告再得",
      "再看一个",
      "再看1个",
    ];
    for (var index = 0; index < contents.length; index++) {
      var content = contents[index];
      var UIText = utils$3.existsTextStartsWith(content);
      if (UIText) {
        console.log("找到-" + content + "-", ",存在下一个广告可看");
        return {
          result: true,
          trigger: function () {
            utils$3.clickUIText(UIText);
          },
        };
      }
    }
    return {
      result: false,
      trigger: function () {},
    };
  }
  function ifAdOverDefault() {
    var UIText = utils$3.existsTextStartsWith("领取成功");
    if (UIText) {
      console.log("找到-领取成功-");
      return UIText;
    }
    var UIText = utils$3.existsTextStartsWith("已领取");
    if (UIText) {
      console.log("找到-已领取-");
      return UIText;
    }
    var UIText = utils$3.existsTextStartsWith("已完成任务 ");
    if (UIText) {
      console.log("找到-已完成任务 -");
      return UIText;
    }
  }
  function existAdDefault() {
    var contents = [
      //prettier-ignore
      "残忍离开",
      "坚持离开",
      "残忍退出",
      "坚持退出",
    ];
    for (var index = 0; index < contents.length; index++) {
      var content = contents[index];
      var UIText = utils$3.existsTextStartsWith(content);
      if (UIText) {
        console.log("找到-" + content + "-，", "关闭广告");
        utils$3.clickUIText(UIText);
      }
    }
  }

  var AD_CONST_MIN_INTERVAL = 40;
  var AD_CONST_MAX_GO_BACK_TIMES = 4;

  var ad = {
    inStart: false,
    inHome: false,
    ifHasNextAd: null, //判断是否有下一个广告
    ifAdOver: null, //判断广告实际是否比预计时间提前结束
    ifInStart: null, //判断是否是在任务页
    ifInHome: null, //判断是否在首页
    hasWatchTimes: 0,
    maxTimes: 0,
    init(maxTimes, ifInStart, ifHasNextAd, ifAdOver, exitAd, ifInHome) {
      this.hasWatchTimes = 0;
      this.maxTimes = utils$3.getRandom(maxTimes, maxTimes + 2);
      this.ifInStart = ifInStart;
      this.ifHasNextAd = ifHasNextAd || ifHasNextAdDefault;
      this.ifAdOver = ifAdOver || ifAdOverDefault;
      this.exitAd = exitAd || existAdDefault;
      this.ifInHome = ifInHome || inHome;
      console.log("ad init: 本轮最多看-" + this.maxTimes + "-个广告");
      this.run();
    },
    run() {
      //开始看广告
      var adSpan = AD_CONST_MIN_INTERVAL + utils$3.getRandom(0, 5);
      console.log(
        //prettier-ignore
        "ad run: 开始看-" + (this.hasWatchTimes+1) + "-个广告，预计时间-" + adSpan + "-s"
      );
      var checkAdOverSpan = 2; //每隔2s检查当前广告是否已经结束
      var isOverEarly = false;
      var hasWatchSpan = 0;
      var count = 0;
      while (adSpan > checkAdOverSpan) {
        if (hasWatchSpan > 30) {
          if (!utils$3.existsTextStartsWith("广告")) {
            console.log(
              //prettier-ignore
              "ad run: 已过-" + hasWatchSpan + "-s但是没找到-广告-,即将执行一次back()"
            );
            back();
            sleep(utils$3.getRandom(2, 2.5, 1000));
          }
        }
        if (this.ifAdOver && this.ifAdOver()) {
          var waitSpan = utils$3.getRandom(2, 3.5);
          console.log("ad run: 广告已结束,再过" + waitSpan + "s后停止当前广告");
          sleep(waitSpan * 1000);
          isOverEarly = true; //广告实际比预计的时间提前结束
          break;
        }
        sleep(checkAdOverSpan * 1000);
        adSpan = adSpan - checkAdOverSpan;
        hasWatchSpan = hasWatchSpan + checkAdOverSpan;
        count = count + 1;
        if (count % 5 == 0) {
          console.log("ad run: 广告时间预计还剩-" + adSpan + "-s");
        }
      }
      this.hasWatchTimes = this.hasWatchTimes + 1;
      if (isOverEarly) {
        this.goBack();
        return;
      }
      if (adSpan > 0) {
        console.log("ad run: 广告时间还剩最后的" + adSpan + "秒");
        sleep(adSpan * 1000);
        this.goBack();
        return;
      }
    },
    goBack() {
      var index = 0;
      while (index < AD_CONST_MAX_GO_BACK_TIMES) {
        console.log("ad goBack: 第" + (index + 1) + "次执行back");
        back();
        sleep(utils$3.getRandom(2.5, 4, 1000));
        var hasNextAd = this.ifHasNextAd();
        if (hasNextAd.result) {
          if (this.hasWatchTimes >= this.maxTimes) {
            console.log(
              //prettier-ignore
              "当前看广告-" + this.hasWatchTimes + "-次，最多看-" + this.maxTimes + "-次，执行exitAd"
            );
            this.exitAd();
            return;
          } else {
            console.log("开始看下一个广告");
            hasNextAd.trigger();
            sleep(utils$3.getRandom(2, 3, 1000));
            this.run();
            return;
          }
        }
        if (this.ifInStart && this.ifInStart()) {
          console.log("ad goBack: 判断在开始页");
          this.inStart = true;
          this.after();
          return;
        }
        if (this.ifInHome && this.ifInHome()) {
          console.log("ad goBack: 判断在app首页");
          this.inHome = true;
          this.after();
          return;
        }
        index = index + 1;
      }
      this.after();
    },
    after() {
      console.log("ad after");
      this.next();
    },
    next() {
      console.log("ad next");
    },
  };

  var storage = utils$3.getStorage(time.str("YYYY-MM-DD") + "百度畅听");
  common$2.toTask = toTask;
  common$2.inHome = inHome;
  common$2.pointMap = pointMap;
  common$2.swipeUp = swipeUp;
  common$2.swipeDown = swipeDown;
  common$2.readArticle = readArticle;
  common$2.ad = ad;
  common$2.storage = storage;

  var ocrGml$1 = ocrGml_1;
  var utils$2 = utils_1;
  var common$1 = common$2;
  function ifInTaskDefault() {
    var ocrItem = ocrGml$1.captureExistOne(["金币收益", "现金收益", "去提现"]);
    return ocrItem;
  }
  var inTask$1 = {
    run(ifInTask, config) {
      this.ifInTask = ifInTask || ifInTaskDefault;
      this.over();
      sleep(utils$2.getRandom(1, 1.5, 1000));
      this.sign();
      sleep(utils$2.getRandom(1, 1.5, 1000));
      if (this.ad()) {
        return;
      }
      sleep(utils$2.getRandom(1, 1.5, 1000));
      if (config && config.fromAward) ; else {
        this.award();
      }
    },
    //领取
    award() {
      var contents = ["领取"];
      var ocrItem = ocrGml$1.captureExistOne(contents, true);
      if (ocrItem) {
        utils$2.clickOcrItem(ocrItem);
        this.run(null, {
          fromAward: true,
        });
      }
    },
    over() {
      var contents = ["开心收下", "立即收下", "我知道了"];
      var ocrItem = ocrGml$1.captureExistOne(contents, true);
      if (ocrItem) {
        utils$2.clickOcrItem(ocrItem);
        sleep(utils$2.getRandom(2, 3, 1000));
        return;
      }
    },
    sign() {
      var contents = ["立即签到"];
      var ocrItem = ocrGml$1.captureExistOne(contents, true);
      if (ocrItem) {
        utils$2.clickOcrItem(ocrItem);
        sleep(utils$2.getRandom(2, 3, 1000));
      }
      var contents = ["直接领取"];
      var ocrItem = ocrGml$1.captureExistOne(contents, true);
      if (ocrItem) {
        utils$2.clickOcrItem(ocrItem);
        sleep(utils$2.getRandom(2, 3, 1000));
      }
      return;
    },
    ad() {
      var contents = ["看广告再", "看视频再", "看广告领", "看视频领"];
      var ocrItem = ocrGml$1.captureExistOne(contents, true);
      if (ocrItem) {
        utils$2.clickOcrItem(ocrItem);
        sleep(utils$2.getRandom(2, 3, 1000));
        common$1.ad.init(2, this.ifInTask);
        sleep(utils$2.getRandom(2, 3, 1000));
        this.run(null, {
          fromAd: true,
        });
        return true;
      }
    },
  };

  var inTask_1 = inTask$1;

  var utils$1 = utils_1;
  var defaultActionConfig = {
    interval: null, //每个多少秒执行一次
    canStartHour: null, //最早可以开始的时间
    canStartHourEnd: null, //最晚可以开始的时间
    lastStartTime: null, //上一次的开始时间
    lastEndTime: null, //上一次的结束时间
    execSCount: 0, //执行成功次数
    execFCount: 0, //执行失败次数
    maxExecSCount: null, //最大成功执行次数
    maxExecFCount: null, //最大失败执行次数
    maxTotalExecCount: null, //最大总执行次数
    storage: null,
  };
  function ACTION(name, config) {
    this.name = name;
    utils$1.merge(this, config || {}, defaultActionConfig);
  }
  ACTION.prototype.getStorage = function () {
    try {
      return JSON.parse(this.storage.get(this.name));
    } catch (e) {
      return {
        lastStartTime: null,
        lastEndTime: null,
        execSCount: 0,
        execFCount: 0,
      };
    }
  };
  ACTION.prototype.updateStorage = function () {
    this.storage.put(
      this.name,
      JSON.stringify({
        lastStartTime: this.lastStartTime,
        lastEndTime: this.lastEndTime,
        execSCount: this.execSCount,
        execFCount: this.execFCount,
      })
    );
  };
  ACTION.prototype.goStart = function () {
    return true;
  };
  ACTION.prototype.beforeExec = function () {
    return true;
  };
  ACTION.prototype.exec = function () {};
  ACTION.prototype.afterExec = function () {};
  ACTION.prototype.beforeEnd = function () {};
  ACTION.prototype.end = function () {};
  ACTION.prototype.afterEnd = function () {};
  ACTION.prototype.canFlow = function () {
    utils$1.merge(this, this.getStorage() || {}, {
      lastStartTime: null,
      lastEndTime: null,
      execSCount: 0,
      execFCount: 0,
    });
    if (this.canStartHour) {
      var hour = new Date().getHours();
      if (hour < this.canStartHour) {
        console.log(this.name, "最早开始时间未到", hour, "/", this.canStartHour);
        return false;
      }
    }
    if (this.canStartHourEnd) {
      var hour = new Date().getHours();
      if (hour >= this.canStartHourEnd) {
        console.log(
          this.name,
          "最晚结束时间已过",
          hour,
          "/",
          this.canStartHourEnd
        );
        return false;
      }
    }
    if (this.interval && this.lastEndTime) {
      var now = Date.now();
      var hasRun = (now - this.lastEndTime) / 1000;
      if (hasRun < interval) {
        console.log(this.name, "间隔时间未到", hasRun, this.interval);
        return false;
      }
    }
    if (this.maxTotalExecCount) {
      if (this.execSCount == this.maxExecSCount) {
        console.log(this.name, "执行成功次数已达上限");
        return false;
      }
      if (this.execSCount + this.execFCount < this.maxTotalExecCount) {
        return true;
      } else {
        console.log(this.name, "总执行次数已达上限");
        return false;
      }
    }
    if (this.maxExecFCount) {
      if (this.execSCount == this.maxExecSCount) {
        console.log(this.name, "执行成功次数已达上限");
        return false;
      }
      if (this.execFCount < this.maxExecFCount) {
        return true;
      } else {
        console.log(this.name, "执行失败次数已达上限");
        return false;
      }
    }
    if (this.maxExecSCount) {
      if (this.execSCount < this.maxExecSCount) {
        return true;
      } else {
        console.log(this.name, "执行成功次数已达上限");
        return false;
      }
    }
    return true;
  };
  ACTION.prototype.flow = function () {
    console.show(true);
    if (!this.canFlow()) {
      sleep(utils$1.getRandom(1.5, 2, 1000));
      console.hide();
      return false;
    }
    if (this.goStart()) {
      var beforeExec = this.beforeExec();
      if (beforeExec) {
        this.exec(beforeExec);
        this.afterExec();
        this.beforeEnd();
        this.end();
        this.afterEnd();
      }
      sleep(utils$1.getRandom(1.5, 2, 1000));
      console.hide();
    } else {
      console.log(this.name, "到达开始页面失败");
      sleep(utils$1.getRandom(1.5, 2, 1000));
      console.hide();
    }
  };

  var action = ACTION;

  var utils = utils_1;
  var ocrGml = ocrGml_1;
  var inTask = inTask_1;
  var common = common$2;
  var Action = action;
  var actionOneAdd1 = new Action("添加活动到桌面", {
    execSCount: 0,
    execFCount: 0,
    maxExecSCount: 1, //最大成功执行次数
    maxExecFCount: 2, //最大失败执行次数
    maxTotalExecCount: 3, //最大总执行次数
    storage: common.storage,
  });
  actionOneAdd1.exec = function () {
    var content = "添加活动到桌面";
    var ocrItem = ocrGml.findTextOne(
      content,
      true,
      null,
      10,
      (device.height / 10) * 2
    );
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
      sleep(utils.getRandom(5, 8, 1000));
      inTask.run();
      this.execSCount++;
      this.updateStorage();
    } else {
      this.execFCount++;
      this.updateStorage();
      console.log("没有找到" + content);
    }
  };
  var aOneAdd1 = actionOneAdd1;

  execTest.actionTest(aOneAdd1);

  return aOneAdd1Test;

})();
